#include "multimeter.h"

Multimeter::Multimeter(QWidget *parent)
    : QWidget(parent)
{
	ui.setupUi(this);
	handleADC = new HandleADC;
	handleDAC = new HandleDAC;
	signalGen = new SignalGen;
	timer = new QTimer(this);

	// timer -> signalGen
	connect(timer, SIGNAL(timeout()), signalGen, SLOT(calcSample()));

	// freqDial -> signalGen
	connect(ui.freqDial, SIGNAL(valueChanged(int)), signalGen, SLOT(setFrequency(int)));

	// voltageDial -> signalGen
	connect(ui.voltageDial, SIGNAL(valueChanged(int)), signalGen, SLOT(setVoltage(int)));

	// combobox waveformtype -> signalGen
	connect(ui.comboBox, SIGNAL(currentIndexChanged(int)), signalGen, SLOT(setWaveformType(int)));

	// signalGen -> handleDAC
	connect(signalGen, SIGNAL(valueChanged(int)), handleDAC, SLOT(updateValue(int)));

	// handleDAC -> lcdDAC
	connect(handleDAC, SIGNAL(valueChanged(int)), ui.lcdDAC, SLOT(display(int)));

	// signalGen -> lcdADC
	connect(signalGen, SIGNAL(valueChanged(int)), ui.lcdADC, SLOT(display(int)));

	handleADC->start();
	handleDAC->start();
	timer->start(250);
}

Multimeter::~Multimeter()
{
	delete handleADC;
	delete handleDAC;
	delete timer;
}
